package com.ruoyi.team.service.impl;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import com.ruoyi.common.exception.ServiceException;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.team.mapper.StoreMapper;
import com.ruoyi.team.domain.Store;
import com.ruoyi.team.service.IStoreService;

/**
 * 仓库信息Service业务层处理
 *
 * @author ruoyi
 * @date 2022-11-27
 */
@Service
public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements IStoreService {

    /**
     * 查询仓库信息列表
     *
     * @param store 仓库信息
     * @return 仓库信息
     */
    @Override
    public List<Store> selectStoreList(Store store) {
        return getBaseMapper().selectStoreList(store);
    }

    @Override
    public List<Store> selectStoreName(Store store) {
        return getBaseMapper().selectStoreName(store);
    }


    @Override
    public boolean save(Store entity) {
        //新增的时候将仓库状态设置为正常
        entity.setState(Store.STORE_STATUS_NORMAL);
        return super.save(entity);
    }

     @Override
    public boolean removeBatchByIds(Collection<?> list) {
         //先查询仓库是否有物品
         for (Object id : list) {
             Store store = getById((Serializable) id);
             Integer count=getBaseMapper().selectAmounts(id);
            if (count==null||count==0){
                store.setState(Store.STORE_STATUS_DELETE);
                super.updateById(store);
                //getBaseMapper().deleteById((Serializable) id);
            }else if (count>0){
                throw new ServiceException("仓库还有物品,无法删除");
            }
         }
      return true;
    }
}
